﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class index : System.Web.UI.Page
{
    public string renderHtml = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        // 数据库连接
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("./database/vote.mdb"));
        OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [web]", conn);
        DataSet ds = new DataSet();
        myDa.Fill(ds);

        // 拿到总票数
        int voteSum = 0;;
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            voteSum += int.Parse(ds.Tables[0].Rows[i]["getvotes"].ToString());
        }

        // 渲染结果
        for (int i = 0; i < ds.Tables[0].Rows.Count;i++ )
        {
            string webName = ds.Tables[0].Rows[i]["webname"].ToString();
            string webVote = ds.Tables[0].Rows[i]["getvotes"].ToString();
            string wenAuthor = ds.Tables[0].Rows[i]["maker"].ToString();
            int voteRate = int.Parse(webVote) * 200 / voteSum;

            renderHtml += "<div><p><span style=\"float:left;width: 300px;\">网站名称：" + webName + "作者：" + wenAuthor + "</span></p>" +
				"<div class=\"jindu\"><div style=\"width:"+ voteRate.ToString() +"px; height:13px; background:url(pic/jindu.png)\"></div></div>"+
                "<p><span>" + webVote + "票</span></p>" +
                "<p>&nbsp; </p>"+
			    "</div>";
        }
        
    }
}
